//初始化
$(function () {
    fetchData();

    $("#btnSearch").click(function () {
        $('#tb').bootstrapTable("refresh",{
            pageNumber:1
        });
    });
});
function fetchData() {
    $('#tb').bootstrapTable({
        method: 'get',
        url: '/goods/Search',
        pagination: true,
        pageNumber: 1,
        height: 500,
        pageSize: 2,
        pageList: [2, 10, 20, 30, 50, 100],
        sidePagination: "server",
        queryParamsType: "page",
        queryParams: function (params) {         //自定义查询条件
            params["goodName"] = $("#goodName").val();
            return params;
        },
        clickToSelect: true,
        columns: [
            {
                title: '货物编号',
                field: 'goodId'
            },
            {
                title: '货物名称',
                field: 'goodName'
            },
            {
                title: '货物类型',
                field: 'goodType'
            },
            {
                title: '货物尺寸',
                field: 'goodSize'
            },
            {
                title: '商品价格',
                field: 'goodPrice'
            },
            {
                title: '操作',
                field: 'goodId',
                formatter: optionTemplate
            },
        ],
        responseHandler: function (res) {
            if (res.code === 1) {
                res = res.data;
            }
            return res;
        }
    });
}

function optionTemplate(value, row, index) {
    let str = `<a class="btn btn-primary" onclick='editMethod(${index})' >修改</a>`;
    return str;
}

function editMethod(index) {
    console.log("编辑");
    let arr = $('#tb').bootstrapTable('getData');
    let data = arr[index];
    console.log(data);
    location.href="/goods/update?goodId="+data.goodId;
    console.log(data);
}
